<?php
/**
 * 登录密码和用户名无刷新验证
 * 
 */
require_once(dirname(__FILE__)."/config.php");

/*******
*
*
* 		登录
*
*/
if($fmdo=='login')
{
	if($dopost=='userid')
	{
		$row = $dsql->GetOne("SELECT mid FROM #@__member WHERE userid='$uid'");
		if($uid=='')
		{
			echo "<em>用户名不能为空</em><script>$('#useridl').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else if(!$row)
		{
			echo "<em>用户名不存在</em><script>$('#useridl').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else
		{
			echo "<script>$('#useridl').css('border-color','green');</script>";
		}
	}
	else if($dopost=='ckpwd')
	{
		$row = $dsql->GetOne("SELECT pwd FROM #@__member WHERE userid='$uid'");
		$npwd = $row['pwd'];
		$npwd = md5($pwd);
		if($pwd=='')
		{
			echo "<em>密码不能为空</em><script>$('#pwdl').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else if($row['pwd']!=$npwd)
		{
			echo "<em>密码错误</em><script>$('#pwdl').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else
		{
			if(preg_match("/2/",$safe_gdopen)){
				echo "<script>$('#pwdl').css('border-color','green');</script>";
			}else{
				echo "<script>$('#pwdl').css('border-color','green');$('#loginsub').attr('disabled',false).css('cursor','pointer');</script>";
			}
		}
	}
	
	//对比验证码
	else if($dopost=='ckvdcode')
	{
		if($vdcode==''){
			echo "<em>验证码不能为空</em><script>$('#vdcode').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
            exit();
		}else{
			if(!isset($vdcode))
			{
				$vdcode = '';
			}
			$svali = GetCkVdValue();
			if(preg_match("/2/",$safe_gdopen))
			{
				if(strtolower($vdcode)!=$svali || $svali=='')
				{
					ResetVdValue();
					echo "<em>验证码错误</em><script>$('#vdcode').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
					exit();
				}
				else
				{
					echo "<script>$('#vdcode').css('border-color','green');$('#loginsub').attr('disabled',false).css('cursor','pointer');</script>";
				}
				
			}
		}
	}
}

/*******
*
*
* 		注册
*
*/
else if($fmdo=='ureg')
{
	//检测用户名是否合格或已存在
	if($dopost=='userid')
	{
		if($uid=='')
		{
			echo "<em>用户名不能为空</em><script>$('#userid').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else if($uid=='盛视网' || $uid=='cgstar' || $uid=='www' || $uid=='bbs' || $uid=='ftp' || $uid=='mail' || $uid=='user' || $uid=='users' || $uid=='admin' || $uid=='administrator')
		{
			echo "<em>用户名中包含禁用字符，请重新输入！</em><script>$('#userid').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else
		{
			$row = $dsql->GetOne("SELECT userid FROM #@__member WHERE userid='$uid'");
			if($row)
			{
				echo "<em>用户名已存在</em><script>$('#userid').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
				exit;
			}
			else
			{
				echo "<script>$('#userid').css('border-color','green');</script>";
			}
		}
	}
	
	//检测密码是否大于8位
	else if($dopost=='userpwd')
	{
		if(strlen($pwd) < 8)
		{
			echo "<em>密码不能少于8位</em><script>$('#userid').css('border-color','green');$('#userpwd').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
		}
		else
		{
			echo "<script>$('#userid').css('border-color','green');$('#userpwd').css('border-color','green');</script>";
		}
	}
	
	//检测两次输入密码是否一致
	else if($dopost=='userpwdok')
	{
		if($pwd != $pwd2)
		{
			echo "<em>两次输入密码不一致</em><script>$('#userid').css('border-color','green');$('#userpwd').css('border-color','green');$('#userpwdok').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
		}
		else
		{
			echo "<script>$('#userid').css('border-color','green');$('#userpwd').css('border-color','green');$('#userpwdok').css('border-color','green');</script>";
		}
	}
	
	//检测邮箱格式是否正确和是否已存在
	else if($dopost=='email')
	{
		$regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[-_a-z0-9][-_a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})$/i';
		if(!preg_match($regex, $email))
		{
			echo "<em>电子邮件格式不正确</em><script>$('#email').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else
		{
			$row = $dsql->GetOne("SELECT email FROM #@__member WHERE email='$email'");
			if($row)
			{
				echo "<em>邮箱已被其他用户注册，请更换一个</em><script>$('#email').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			}
			else
			{
				if(preg_match("/1/",$safe_gdopen)){
					echo "<script>$('#email').css('border-color','green');</script></script>";
				}else{
					echo "<script>$('#email').css('border-color','green');$('#loginsub').attr('disabled','').css('cursor','pointer');</script></script>";
				}
			}
		}
	}
	
	//对比验证码
	else if($dopost=='ckvdcode')
	{
		if($vdcode==''){
			echo "<em>验证码不能为空</em><script>$('#vdcode').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
            exit();
		}else{
			if(!isset($vdcode))
			{
				$vdcode = '';
			}
			$svali = GetCkVdValue();
			if(preg_match("/1/",$safe_gdopen))
			{
				if(strtolower($vdcode)!=$svali || $svali=='')
				{
					ResetVdValue();
					echo "<em>验证码错误</em><script>$('#vdcode').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
					exit();
				}
				else
				{
					echo "<script>$('#vdcode').css('border-color','green');$('#loginsub').attr('disabled',false).css('cursor','pointer');</script>";
				}
				
			}
		}
	}
	
}


/*******
*
*
* 		找回密码
*
*/
else if($fmdo=='reseck')
{
	if($dopost=='ckmail')
	{
		$row = $dsql->GetOne("SELECT mid FROM #@__member WHERE email='$mail'");
		
		$regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[-_a-z0-9][-_a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})$/i';
		if(!preg_match($regex, $mail))
		{
			echo "<em>电子邮件格式不正确</em><script>$('#mail').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else if(!$row)
		{
			echo "<em>邮箱不存在</em><script>$('#mail').css('border-color','red');$('#loginsub').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else
		{
			echo "<script>$('#mail').css('border-color','green');$('#loginsub').attr('disabled',false).css('cursor','pointer');</script>";
		}
	}
	
	//密码对比
	else if($dopost=='ckpwd')
	{
		if($pwd=='')
		{
			echo "<em>新密码不能为空</em><script>$('#pwdrese').css('border-color','red');$('#subrese').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			exit;
		}
		else
		{
			if(strlen($pwd) < 8)
			{
				echo "<em>密码长度不能小于8位</em><script>$('#pwdrese').css('border-color','red');$('#subrese').attr('disabled','disabled').css('cursor','not-allowed');</script>";
			}
			else
			{
				echo "<script>$('#pwdrese').css('border-color','green');</script>";
			}
		}
	}
	else if($dopost=='ckpwd2')
	{
		if($pwd!=$pwdok)
		{
			echo "<em>两次密码不一致</em><script>$('#pwdokrese').css('border-color','red');$('#subrese').attr('disabled','disabled').css('cursor','not-allowed');</script>";
		}
		else
		{
			echo "<script>$('#pwdokrese').css('border-color','green');$('#subrese').attr('disabled',false).css('cursor','pointer');</script>";
		}
	}
}